import {MealRequest, MealResponse, MealType} from "@/api/types/meal";
import {BaseResponse} from "@/api/types/baseResponse";
import request from "@/utils/request";

// 公用的 API 地址
const URL = "/meal/meal"

// 根据出餐中心ID和套餐类型查询套餐
export async function getMealsByMealCenterIdAndMealType(mealCenterId: number, mealType: MealType) {
    return await request.get<BaseResponse<MealResponse[]>, BaseResponse<MealResponse[]>>("/meal/webgetmeal", {
        params: {
            mealcenterid: mealCenterId,
            mealtype: mealType
        }
    })
}

// 根据ID查询套餐
export async function getMealById(id: number) {
    return await request.get<BaseResponse<MealResponse[]>, BaseResponse<MealResponse[]>>(URL, {params: {id}})
}

// 增加套餐
export async function addMeal(data: MealRequest) {
    return await request.post<BaseResponse<[]>, BaseResponse<[]>>(URL, data)
}

// 修改套餐
export async function updateMeal(data: MealRequest) {
    return await request.put<BaseResponse<boolean>, BaseResponse<boolean>>(URL, data)
}

// 根据ID删除套餐
export async function deleteMealById(id: number) {
    return await request.delete<BaseResponse<boolean>, BaseResponse<boolean>>(URL, {data: {id}})
}

// 上传套餐图片
export async function uploadMealPicture(pictureBase64: string, path: string) {
    return await request.post<BaseResponse<string>, BaseResponse<string>>("/meal/picture", {
        avatarUrlBase64: pictureBase64,
        path: path
    })
}
